#include<bits/stdc++.h>
using namespace std;

signed main() {
	int t;
	cin >> t;
	while (t--) {
		int time, h, m;
		scanf("%d %d:%d", &time, &h, &m);
		int ddl = h * 60 + m - time;
		printf("%d:%d\n", ddl / 60, ddl % 60);
	}
	return 0;
}
